Technical Q&As


The Apple Media Tool and Apple Media Tool Programming Environment products have been discontinued. For more information check out: AMT/PE Discontinued.

AMT_PE 04 - Multiple Fields with a Single .PAR File (1-June-95)


Q We want our application to have a survey screen containing approximately 10 fields that the user is asked to fill out. It seems very inefficient to have a separate .PAR file on the disk for each field, since the .PAR files will be empty (the empty fields still take time to load). Is there any way to have multiple editable fields refer to the same .PAR file without interfering with each other?

A The following C code has a field which can be left void for an initial value, so you can have a FIELDSUPPLIER with no media target:
-- MYFIELDSUPPLIER - a class to support editable text without any 
-- media associated with it.

class MYFIELDSUPPLIER is FIELDSUPPLIER;
has
     initialValue;

     LoadData()
          external "MyFieldSupplierLoadData";     
          
     UnloadData()
          do
          end;
     
     UninstallData(theContainer, theClient)
          do
          end;
end;

--------------------------------------
(myfield.c:)
------------

/*
  File: MyField.c
     supports fieldsuppliers with no media.
  (derived from Texthandler.c)
*/

#include "Errors.h"
#include "Fonts.h"
#include "Memory.h"
#include "QuickDraw.h"
#include "TextEdit.h"

#include "Key.h"

typedef struct {  
     short font;
     short size;               /* points */
     short face;
     short kerning;            /* tenth of points */
     short firstSpacing;       /* points */
     short nextSpacing;        /* points */
     short leftMargin;
     short topMargin;
     short rightMargin;
     short bottomMargin;
     short alignment;
     RGBColor backColor;
     RGBColor foreColor;
     short transparent;
} KTextStyle,  *KTextStylePtr;

extern const keyID K_INITIALVALUE ; // kate
extern const keyID K_DATA;

Handle MyFieldSupplierLoadData(key* the)
{
     Handle aHandle = NULL;
     long aCount;
     RGBColor fgcolor, bgcolor;
     key* a = keyUse(1);
     
     keyDo {
          
          GetBackColor(&bgcolor);
          GetForeColor(&fgcolor);

          a[0] = keyGet(the[SELF], K_INITIALVALUE);
          if (keyIsVoid(a[0]))  // forgot to initialize it, try to be nice
               aCount = 0;
          else
               aCount = strlen(keyToString(a[0])); // K_INITIALVALUE better be a STRING!

          aHandle = NewHandleClear(sizeof(KTextStyle) + sizeof(long));
          keyIfNULL(aHandle);
          HLock(aHandle);
          ((KTextStylePtr)(*aHandle))->font = helvetica;    
          ((KTextStylePtr)(*aHandle))->size = 14; 
          ((KTextStylePtr)(*aHandle))->face = normal; 
          ((KTextStylePtr)(*aHandle))->kerning = 0; // tenth of points
          ((KTextStylePtr)(*aHandle))->firstSpacing = 0; // fontAscent - points - let
fieldSupplierInstall figure it out
          ((KTextStylePtr)(*aHandle))->nextSpacing = 0; //line height - points - let
fieldSupplierInstall figure it out
          ((KTextStylePtr)(*aHandle))->leftMargin = 4; // pixels???
          ((KTextStylePtr)(*aHandle))->topMargin = 4; 
          ((KTextStylePtr)(*aHandle))->rightMargin =  4; 
          ((KTextStylePtr)(*aHandle))->bottomMargin =  4; 
          ((KTextStylePtr)(*aHandle))->alignment = teFlushDefault; 
          ((KTextStylePtr)(*aHandle))->backColor = bgcolor;
          ((KTextStylePtr)(*aHandle))->foreColor = fgcolor;
          ((KTextStylePtr)(*aHandle))->transparent = 1; 
          HUnlock(aHandle);

          *((long*)(*aHandle + sizeof(KTextStyle))) = aCount;
          if (aCount & 1) aCount++;
          SetHandleSize(aHandle, sizeof(KTextStyle) + sizeof(long) + aCount);
          keyIfError(MemError());
          
          if (aCount) {
               HLock(aHandle);
               strcpy((char*)(*aHandle + sizeof(KTextStyle) + sizeof(long)),
keyToString(a[0]));
               HUnlock(aHandle);
          }
          keyPut(the[SELF], K_DATA, keyFromHandle(aHandle));
     }
     keyUndo {
          if (aHandle != NULL) DisposHandle(aHandle);
     }

}


Technical Q&As
Previous Question | Contents | Next Question